A lexical analysis program for a small language

Source: Internet
Author: User
Tags constant knowledge base

A few days ago wrote a small language lexical analysis program, because a few days ago in the VC knowledge Base to see a Pascal lexical analysis of the procedure, feel very complex to write. In fact, the principle of lexical analysis procedures are the same, so I think as long as you understand the simple lexical analysis procedures, and then write complex is not difficult, nothing more than a few more keywords, write a few conditions to judge the sentence. Lexical analysis is the basis of the compiler program, but also the simplest. OK, now let's see the procedure.

Let's take a look at the grammar of the small language first.

g[< Program]:

< procedure >∷=< procedure First >;< sub-procedure.

< program header >∷=program< identifier >

< procedures >∷=< Compound statements >

< compound statement >∷=begin< statement sequence >end

< statement sequence >∷=< statement >{;< statement

< statement >∷=< Assignment statement >|< Compound statement >|< conditional Statement >

< Assignment statement >∷=< identifier >:=< expression >

< conditional statement >∷=if < Boolean expression > then < statement > Else < statement >

< expression >∷=< Item >{(+|-) < key

< >∷=< >{(*|/) <-type

< >∷=< identifier >|< unsigned constant >| ' (' < expression > ') '

< Boolean expression >∷=< expression >< relational operator >< expression >

< relational operator >∷= =|<|<=|>|>=|<>

< identifiers >∷=< Letters >{< letters >|< Numbers}

< unsigned constant >∷=< digital >{< digital >}[.< Digital >{<

< letter >∷=a|b|c|d|e|f|g|......| U|v|w|x|y|z

< digital >∷=0|1|2|3|4|5|6|7|8| 9

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.