From e2700665d0a5ee0a62f22369a07c5e748a9977b6 Mon Sep 17 00:00:00 2001 From: Kelvin Sherlock Date: Sun, 18 Aug 2013 21:09:17 -0400 Subject: [PATCH] move semi-colon commands to their own state --- bin/lexer.rl | 43 +++++++++++++++++++++++++++---------------- bin/parser.lemon | 14 +++++++------- 2 files changed, 34 insertions(+), 23 deletions(-) diff --git a/bin/lexer.rl b/bin/lexer.rl index f7d0967..1944179 100644 --- a/bin/lexer.rl +++ b/bin/lexer.rl @@ -105,6 +105,27 @@ namespace { # this exits with cs == lexer_en_error. error := any* ${ fbreak; }; + # semi-colon commands. + semi := |* + + [ \t\r\n]+; + + 'h'i | 'hd'i | 'hexdump'i { + Parse(parser, tkSEMIH, 0, command); + }; + + 'i'i | 'info'i { + Parse(parser, tkSEMII, 0, command); + }; + + 'l'i | 'list'i { + Parse(parser, tkSEMIL, 0, command); + }; + + + + *|; + main := |* [ \t\r\n]+; @@ -136,8 +157,14 @@ namespace { '>' { Parse(parser, tkGT, 0, command); }; ':' { Parse(parser, tkCOLON, 0, command); }; + '@' { Parse(parser, tkAT, 0, command); }; + ';' { + Parse(parser, tkSEMI, 0, command); + fgoto semi; + }; + '$' xdigit + { uint32_t value = scan16(ts + 1, te); @@ -261,22 +288,6 @@ namespace { }; - # TODO - split the ; commands into two parts. - # struct Token {std::string sValue; uint32_t intValue; enum Command { dump, list, ... }}; - ';h'i | ';hd'i | ';hexdump'i { - Parse(parser, tkSEMIH, 0, command); - }; - - ';i'i | ';info'i { - Parse(parser, tkSEMII, 0, command); - }; - - ';l'i | ';list'i { - Parse(parser, tkSEMIL, 0, command); - }; - - - # generic identifier # since % is a valid character, should drop %/modulo operator. [%_A-Za-z][%_.A-Za-z0-9]* { diff --git a/bin/parser.lemon b/bin/parser.lemon index 34d418b..b723ea1 100644 --- a/bin/parser.lemon +++ b/bin/parser.lemon @@ -158,39 +158,39 @@ stmt ::= LIST expr(a) EOL. } -stmt ::= expr(a) SEMIH EOL. +stmt ::= expr(a) SEMI SEMIH EOL. { Debug::Dump(a.intValue); } -stmt ::= expr(a) COLON expr(b) SEMIH EOL. +stmt ::= expr(a) COLON expr(b) SEMI SEMIH EOL. { Debug::Dump(a.intValue, b.intValue - a.intValue); } -stmt ::= expr(a) AT expr(b) SEMIH EOL. +stmt ::= expr(a) AT expr(b) SEMI SEMIH EOL. { Debug::Dump(a.intValue, b.intValue); } -stmt ::= expr(a) SEMII EOL. +stmt ::= expr(a) SEMI SEMII EOL. { MM::Native::MemoryInfo(a.intValue); } -stmt ::= expr(a) SEMIL EOL. +stmt ::= expr(a) SEMI SEMIL EOL. { Debug::List(a.intValue); } -stmt ::= expr(a) AT expr(b) SEMIL EOL. +stmt ::= expr(a) AT expr(b) SEMI SEMIL EOL. { Debug::List(a.intValue, (int)b.intValue); } -stmt ::= expr(a) COLON expr(b) SEMIL EOL. +stmt ::= expr(a) COLON expr(b) SEMI SEMIL EOL. { Debug::List(a.intValue, b.intValue); }