Permalink
Browse files

Try to automatically finish parsing with EOL.

Does not quit work yet. :-(
  • Loading branch information...
1 parent e77720f commit 166d26471a194a3fb12e0f09c5aec340e2157d6f @theory committed Jan 30, 2013
Showing with 25 additions and 9 deletions.
  1. +6 −3 main.c
  2. +16 −3 shellparser.y
  3. +3 −3 shellscanner.l
View
9 main.c
@@ -10,7 +10,6 @@ void* Parse(void*, int, const char*);
void* ParseFree(void*, void(*freeProc)(void*));
int main(int argc, char** argv) {
- printf("> ");
// Set up the scanner
yyscan_t scanner;
yylex_init(&scanner);
@@ -19,11 +18,15 @@ int main(int argc, char** argv) {
// Set up the parser
void* shellParser = ParseAlloc(malloc);
+ // Do it!
+ printf("> ");
int lexCode;
do {
lexCode = yylex(scanner);
- Parse(shellParser, lexCode, NULL);
- if (lexCode == EOL) printf("> ");
+ Parse(shellParser, lexCode, yyget_text(scanner));
+ // XXX This line should not be necessary; EOL should automatically
+ // terminate parsing. :-(
+ if (lexCode == EOL) Parse(shellParser, 0, NULL);
} while (lexCode > 0);
if (-1 == lexCode) {
View
@@ -10,34 +10,47 @@
fprintf(stderr, "Error parsing command\n");
}
-start ::= commandList .
+start ::= in .
+in ::= .
+in ::= in commandList EOL .
{
+ printf("start ::= commandList .\n");
+ printf("> ");
}
-commandList ::= command PIPE commandList EOL .
+
+commandList ::= command PIPE commandList .
{
+ printf("commandList ::= command PIPE commandList .\n");
}
-commandList ::= command EOL .
+commandList ::= command .
{
+ printf("commandList ::= command .\n");
}
command ::= FILENAME argumentList .
{
+ printf("command ::= FILENAME argumentList .\n");
}
command ::= FILENAME .
{
+ printf("command ::= FILENAME .\n");
}
argumentList ::= argument argumentList .
{
+ printf("argumentList ::= argument argumentList .\n");
}
argumentList ::= argument .
{
+ printf("argumentList ::= argument .\n");
}
argument ::= ARGUMENT .
{
+ printf("argument ::= ARGUMENT .\n");
}
argument ::= FILENAME .
{
+ printf("argument ::= FILENAME .\n");
}
View
@@ -10,12 +10,12 @@
%%
-"|" { printf("PIPE\n"); return PIPE; }
+"|" { return PIPE; }
[ \t\r] { }
-\n { return EOL; }
+[\n] { return EOL; }
-[a-zA-Z0-9_\.\-]+ { printf("FILENAME: \"%s\"\n", yytext); return FILENAME; }
+[a-zA-Z0-9_\.\-]+ { return FILENAME; }
['] { BEGIN(SINGLE_QUOTED); }
<SINGLE_QUOTED>[^']+ { }

0 comments on commit 166d264

Please sign in to comment.