Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
robotis_motion_pages
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
humanoides
robotis_motion_pages
Commits
16f85546
Commit
16f85546
authored
11 years ago
by
Sergi Hernandez
Browse files
Options
Downloads
Patches
Plain Diff
Added a C version of the motion file parser.
parent
f8ec54b6
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/parser/Makefile
+19
-0
19 additions, 0 deletions
src/parser/Makefile
src/parser/motion_file.l
+33
-0
33 additions, 0 deletions
src/parser/motion_file.l
src/parser/motion_file.y
+120
-0
120 additions, 0 deletions
src/parser/motion_file.y
with
172 additions
and
0 deletions
src/parser/Makefile
0 → 100644
+
19
−
0
View file @
16f85546
LEXOR
=
motion_file
PARSER
=
motion_file
all
:
$(PARSER)
$(PARSER)
:
$(PARSER).tab.c $(LEXOR).yy.c
gcc
-o
$(
PARSER
)
$(
PARSER
)
.tab.c
$(
LEXOR
)
.yy.c
-ly
-ll
-lm
$(PARSER).tab.c
:
$(PARSER).y
bison
-vd
$(
PARSER
)
.y
$(LEXOR).yy.c
:
$(LEXOR).l
flex
-o
$(
LEXOR
)
.yy.c
$(
LEXOR
)
.l
clean
:
rm
-f
$(
LEXOR
)
.yy.c
rm
-f
$(
PARSER
)
.output
rm
-f
$(
PARSER
)
.tab.
*
rm
-f
$(
PARSER
)
This diff is collapsed.
Click to expand it.
src/parser/motion_file.l
0 → 100644
+
33
−
0
View file @
16f85546
%{
#include "motion_file.tab.h"
/* Here we recoginze the various letters that are part of your language.
*/
void yyerror(char *s)
{
printf("Parse error: %s\n",s);
// might as well halt now:
exit(-1);
}
%}
%%
[ \t] ;
type { return TYPE; }
version { return VERSION; }
enable { return ENABLE; }
motor_type { return MOTOR_TYPE; }
page_begin { return BEGIN_PAGE; }
name { return NAME; }
compliance { return COMPLIANCE; }
play_param { return PLAY_PARAMS; }
step { return STEP; }
page_end { return END_PAGE; }
= { return EQUAL; }
[0-9]+\.[0-9]+ { yylval.fval=atof(yytext); return FLOAT; }
[0-9]+ { yylval.ival=atoi(yytext); return INT; }
[a-zA-Z0-9]+ { char *res=(char *)malloc(strlen(yytext)+1);
strcpy(res,yytext);
yylval.sval=res;
return STRING; }
. ;
%%
This diff is collapsed.
Click to expand it.
src/parser/motion_file.y
0 → 100644
+
120
−
0
View file @
16f85546
%{
#include <stdio.h>
int num_servos=0;
int num_pages=0;
int num_steps=0;
%}
%token TYPE VERSION ENABLE MOTOR_TYPE BEGIN_PAGE END_PAGE
%token NAME COMPLIANCE PLAY_PARAMS STEP
%token EQUAL
%union {
int ival;
float fval;
char *sval;
}
%token <ival> INT
%token <fval> FLOAT
%token <sval> STRING
%%
motion_file: type version enables motor_types pages { printf("Processed %d pages\n",num_pages); }
;
type: TYPE EQUAL STRING { printf("Type: %s\n",$3); }
;
version: VERSION EQUAL FLOAT { printf("version: %f\n",$3); }
;
enables: ENABLE EQUAL enable { printf("num servos (enable): %d\n",num_servos);
num_servos=0; }
;
enable: enable INT { num_servos++; }
| INT { num_servos++; }
;
motor_types:
| MOTOR_TYPE EQUAL motor_type { printf("num servos (motor_type): %d\n",num_servos);
num_servos=0; }
;
motor_type: motor_type INT { num_servos++; }
| INT { num_servos++; }
;
pages: pages page { num_pages++; }
| page { num_pages++; }
;
page: BEGIN_PAGE name compliances params steps END_PAGE { printf("page %d num steps %d\n",num_pages,num_steps);
num_steps=0;
num_servos=0; }
| BEGIN_PAGE name compliances params END_PAGE { printf("page %d with no steps\n",num_pages);
num_steps=0;
num_servos=0; }
;
name: NAME EQUAL { printf("page %d has no name\n",num_pages); }
| NAME EQUAL strings { printf("page %d name:\n", num_pages); }
;
strings: strings STRING
| STRING
;
compliances: COMPLIANCE EQUAL compliance { printf("page %d num servos (compliance): %d\n",num_pages,num_servos);
num_servos++; }
;
compliance: compliance INT { num_servos++; }
| INT { num_servos++; }
;
params: PLAY_PARAMS EQUAL INT INT INT FLOAT INT { printf("page %d next motion: %d\n",num_pages,$3);
printf("page %d exit motion: %d\n",num_pages,$4);
printf("page %d repetitions: %d\n",num_pages,$5);
printf("page %d speed rate: %f\n",num_pages,$6);
printf("page %d inertial force: %d\n",num_pages,$7); }
;
steps: steps step { num_steps++; }
| step { num_steps++; }
;
step: STEP EQUAL angles FLOAT FLOAT { printf("page %d step %d pause time: %f\n",num_pages,num_steps,$4);
printf("page %d step %d step time: %f\n",num_pages,num_steps,$5); }
;
angles: angles INT
| INT
;
%%
extern FILE *yyin;
int main(int argc, char *argv[])
{
FILE *file;
printf("parsing example.\n");
if(argc!=2)
{
printf("A motion file mist be provided as an argument.\n");
return -1;
}
file=fopen(argv[1],"r");
if(file==NULL)
{
printf("Impossible to open the file %s\n",argv[1]);
return -1;
}
yyin=file;
do {
yyparse ();
}while(!feof(yyin));
return 0;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment