Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pull request 1 #2

Open
wants to merge 36 commits into
base: Linux
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
88d7caa
Update main.cpp
martincorona007 Sep 30, 2019
d79f76a
update
martincorona007 Sep 30, 2019
cf03e06
update 1
martincorona007 Sep 30, 2019
5f8d422
update 2
martincorona007 Sep 30, 2019
dbf421d
update 3
martincorona007 Sep 30, 2019
74c0445
update 4
martincorona007 Oct 1, 2019
82d3a47
update 5 adding reserved words
martincorona007 Oct 7, 2019
dae4d08
update 6 few adjustments
martincorona007 Oct 8, 2019
621904b
update 7
martincorona007 Oct 9, 2019
ad3ad09
update 8
martincorona007 Oct 10, 2019
85504dc
update 9
martincorona007 Oct 10, 2019
e3c163f
update 10 adding reserved words
martincorona007 Oct 10, 2019
432109e
update 12
martincorona007 Oct 11, 2019
da581a4
update 8.1
martincorona007 Oct 14, 2019
c31cc0c
update 8.2 adding reserved words
Oct 17, 2019
4f25ab6
update 8.3 adding reserved words
Oct 17, 2019
1e73c21
update 8.4 calculate lenght
Oct 20, 2019
88ac87f
update 8.5 adding words to the casting
Oct 21, 2019
1bf1c6c
update
Oct 27, 2019
7339d89
update 5.
Oct 31, 2019
153daa1
update v8.3 making changes
Nov 3, 2019
3c82ba1
update v8.4 solving one part of eof
Nov 3, 2019
ca4e164
update v8.5 adding reserved words
Nov 5, 2019
068acd2
update v8.6 octal, hex,real
Nov 5, 2019
86c497f
update v8.7
Nov 6, 2019
dd101ed
update v8.8
Nov 6, 2019
83562ea
update v8.9
Nov 6, 2019
6c06354
update v8.10 adding operators
Nov 7, 2019
e93efad
v8.2 upgrade
martincorona007 Jan 7, 2020
d625844
v8.3 EOF and solving N newlines
martincorona007 Jan 9, 2020
e79b149
v8.4 solving EOF first in id
martincorona007 Jan 9, 2020
9c75545
v8.5 EOF solved for A1, A2 and A3
martincorona007 Jan 10, 2020
e2d3c6b
v8.6 adding total lines
martincorona007 Jan 10, 2020
8685231
v8.7 adding A4 comments
martincorona007 Jan 11, 2020
92dc26e
v8.8 adding Token Error
martincorona007 Jan 11, 2020
c0decec
Update README.md
martincorona007 Jan 12, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file modified .gitignore
100644 → 100755
Empty file.
2 changes: 2 additions & 0 deletions Lexical_analysis.cbp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
<Add option="-fexceptions" />
</Compiler>
<Unit filename="main.cpp" />
<Unit filename="scanner.cpp" />
<Unit filename="scanner.hpp" />
<Extensions>
<code_completion />
<envvars />
Expand Down
25 changes: 25 additions & 0 deletions Lexical_analysis.depend
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,28 @@
<stdlib.h>
<ctype.h>

1571616720 source:c:\users\martin\documents\github\lexical_analysis\main.cpp
"scanner.hpp"

1571616845 c:\users\martin\documents\github\lexical_analysis\scanner.hpp
<stdio.h>
<stdlib.h>
<ctype.h>

1571630038 source:c:\users\martin\documents\github\lexical_analysis\scanner.cpp
"scanner.hpp"

1572506714 source:c:\users\alien\documents\github\lexical_analysis\main.cpp
"scanner.hpp"

1572505997 c:\users\alien\documents\github\lexical_analysis\scanner.hpp
<stdio.h>
<stdlib.h>
<ctype.h>

1572508676 source:c:\users\alien\documents\github\lexical_analysis\scanner.cpp
"scanner.hpp"

1572496640 c:\users\alien\documents\github\lexical_analysis\scanner.cpp
"scanner.hpp"

18 changes: 12 additions & 6 deletions Lexical_analysis.layout
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@
<CodeBlocks_layout_file>
<FileVersion major="1" minor="0" />
<ActiveTarget name="Debug" />
<File name="main.cpp" open="1" top="1" tabpos="1" split="0" active="1" splitpos="0" zoom_1="2" zoom_2="0">
<File name="scanner.cpp" open="1" top="1" tabpos="2" split="0" active="1" splitpos="0" zoom_1="5" zoom_2="0">
<Cursor>
<Cursor1 position="3368" topLine="103" />
<Cursor1 position="361" topLine="114" />
</Cursor>
</File>
<File name="scanner.hpp" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="214" topLine="14" />
</Cursor>
</File>
<File name="main.cpp" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="2" zoom_2="0">
<Cursor>
<Cursor1 position="58" topLine="0" />
</Cursor>
<Folding>
<Collapse line="72" />
<Collapse line="83" />
</Folding>
</File>
</CodeBlocks_layout_file>
3 changes: 2 additions & 1 deletion README.md
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
# Lexical_analysis
# Lexical_analysis
In this blog I explain this pratice https://medium.com/@martincorona007/lexical-analysis-13f3b517854b
Binary file added main
Binary file not shown.
205 changes: 38 additions & 167 deletions main.cpp
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,170 +1,41 @@
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
//VARS

FILE *file_p;
int udef=4;
long q=0;
//FUNCTIONS
int S(int);
bool udfa();
bool identifier();
bool EOFF();
char read();
void fail();
void sucess();
void full_back();
void tokenn();
bool jump();
int main()
{
char c;
printf("ka");
file_p=fopen("text.txt","r");
/* while((c=fgetc(file_p))!=EOF){
printf("%c",c);
}
*/

tokenn();
fclose(file_p);
#include "scanner.hpp"
int main(){
open("text.txt");
sequential tokenn;

do
{
tokenn=next();
switch(tokenn){
case 0: printf("Identificator");break;
case 1: printf("EOF \n\nThe analysis had finished.");printf("\n==========Total Lines: %i========= ",lines());break;
case 2: printf("ERR");printf("Error in line : %i ",lines());break;
case 3: printf("Reserved word");break;
case 4: printf("Octal number"); break;
case 5: printf("Hexadecimal"); break;
case 6: printf("Real number"); break;
case 7: printf("Delimitation character Left parenthesis"); break;
case 8: printf("Delimitation character Right parenthesis"); break;
case 9: printf("Delimitation character Left bracket"); break;
case 10: printf("Delimitation character Right bracket"); break;
case 11: printf("Arithmetic operator sum");break;
case 12: printf("Arithmetic operator substraction");break;
case 13: printf("Arithmetic operator multiplication");break;
case 14: printf("Arithmetic operator division"); break;
case 15: printf("Puntuation sign comma");break;
case 16: printf("Puntuation sign semicolon"); break;
case 17: printf("Assign operator colon"); break;
case 18: /*printf("comments");*/ break;
/*case 1: printf("Identificator");break;
case 2: printf("Reserved word");break;




case 7: printf("END File");*/
}

} while (tokenn!=_eof && tokenn!=_err);

return 0;
}
char read(){
return fgetc(file_p);
}
void fail(){
fseek(file_p,q,SEEK_SET);
}
void sucess(){
q=ftell(file_p);
}
void full_back(){
fseek(file_p,-1,SEEK_CUR);
}
bool EOFF(){
if(read()==EOF){
full_back();
return true;
}
full_back();
return false;
}
bool jump(){
while(isspace(read()))
full_back();
sucess();
return true;
}
void tokenn(){
jump();

do{
if(identifier()){
printf("identifier");
}else{
printf("error 4004");
}

}while(EOFF());
}
/*
bool udfa(){
int actual=0,prior=0;
actual=0;
while(actual!=udef){
prior=actual;
actual=S(actual);

}
return prior==2;
}*/
/*
int S(int q){
int state=0;

switch(q){

case 0:
if(read()==A){
state=2;
}else if(read()==sub){
state=1;
}else{
state=udef;
}

break;
case 1:
if((read()==N)||(read()==sub)){
state=1;
}else if(read()==A){
state=2;
}else{
state=udef;
}
break;
case 2:
if((read()==A)||(read==N)||(read==sub)){
state=2;
}else{
state=udef;
}

break;
default: state=udef;
}
return state;
}*/
bool identifier(){
int prior=0;
int actual=0;
char c;
while(actual!=udef){
prior=actual;
c=read();

switch(actual){

case 0:
if((read()>=97||read()<=122)||(read()>=65||read()<=90)){
actual=2;
}else if(read()==' '){
actual=1;
}else{
actual=udef;
}

break;
case 1:
if((read()>=48||read()<=57)||(read()==' ')){
actual=1;
}else if((read()>=97||read()<=122)||(read()>=65||read()<=90)){
actual=2;
}else{
actual=udef;
}
break;
case 2:
if(((read()>=97||read()<=122)||(read()>=65||read()<=90))||(read()>=48||read()<=57)||(read()==' ')){
actual=2;
}else{
actual=udef;
}

break;

}
}
if(prior==2){
full_back();
sucess();

return true;
}
fail();

return false;
}
Loading